import json
import requests
import botpy
from botpy.types.message import Message
import e


class ExamplePlugin:
    def priority(self):  # 优先级
        return 1

    def should_trigger(self, message: Message, event):
        # 判断是否触发插件逻辑的条件
        result = False  # 初始化结果变量
        if hasattr(message, 'content'):
            if not message.content is None:
                result = message.content.startswith("机器人") and event == 0
            else:
                result = False and event == 0
        return result

    async def execute(self, message: Message, api, event):

        msg = message.content.replace("机器人", "", 1)  # 请替换为具体的消息内容
        url = 'https://api.binjie.fun/api/generateStream'
        headers = {
            'authority': 'api.binjie.fun',
            'accept': 'application/json, text/plain, */*',
            'accept-encoding': 'gzip, deflate, br',
            'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
            'content-type': 'application/json',
            'origin': 'https://chat3.aichatos.top',
            'referer': 'https://chat3.aichatos.top/',
            'sec-ch-ua': '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': 'Windows',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'cross-site',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35',
        }

        data = {
            'prompt': msg,
            'stream': False,
            'system': '',
            'withoutContext': True
        }
        response = requests.post(url, headers=headers, data=json.dumps(data))
        result = response.content.decode('utf-8')
        if response.status_code == 200:
            print(result)
        else:
            print('请求失败，状态码：', response.status_code)
        await e.reply(api, message, result)

        return False
